package com.cq.hd.admin.controller;

import com.cq.hd.admin.biz.UploadBiz;
import com.cq.hd.common.response.ResultGenerator;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

@Api(tags = "文件上传相关接口")
@Slf4j
@RestController
@RequestMapping("/upload")
public class UploadController extends BaseController {

    @Autowired
    private UploadBiz uploadBiz;

    @ApiOperation(value = "上传图片")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "上传图片用途:0-其他，1-用户/商户/商家相关，2-活动，3-商品，4-反馈，5-文章", paramType = "path", dataType = "Integer")
    })
    @PostMapping("/upload/{type}")
    public Object upload(MultipartFile file, @PathVariable("type") Integer type, HttpServletRequest request) {
        return ResultGenerator.success(uploadBiz.upload(file, type, request));
    }


}
